package com.qfedu.meidijiaju.service.impl;

import com.qfedu.meidijiaju.common.ResponseData;
import com.qfedu.meidijiaju.entity.HuatiYxy;
import com.qfedu.meidijiaju.mapper.HuatiYxyMapper;
import com.qfedu.meidijiaju.service.HuatiYxyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 话题 服务实现类
 * </p>
 *
 * @author meidimeiju
 * @since 2022-10-03
 */
@Service
public class HuatiYxyServiceImpl extends ServiceImpl<HuatiYxyMapper, HuatiYxy> implements HuatiYxyService {

    @Autowired
    private HuatiYxyMapper huatiYxyMapper;


    @Override
    public ResponseData<List<HuatiYxy>> queryAllHuaTi() {


        ResponseData<List<HuatiYxy>> responseData = new ResponseData<>();

        List<HuatiYxy> huatiYxyList = huatiYxyMapper.queryAllHuaTi();

        if (huatiYxyList != null && huatiYxyList.size() > 0){

            responseData.setCode(200);

            responseData.setData(huatiYxyList);
        } else {

            responseData.setCode(400);

            responseData.setMsg("无话题！");
        }

        return responseData;
    }

    @Override
    public ResponseData<List<HuatiYxy>> findHuaTiByHuaTiName(String huaTiName) {

        ResponseData<List<HuatiYxy>> responseData = new ResponseData<>();

        if (!StringUtils.isEmpty(huaTiName)){

            List<HuatiYxy> huatiYxyList = huatiYxyMapper.findHuaTiByHuaTiName("%"+huaTiName+"%");

            if (huatiYxyList != null && huatiYxyList.size() > 0){

                responseData.setCode(200);

                responseData.setData(huatiYxyList);

            } else {


                responseData.setCode(400);

                responseData.setMsg("无关于该话题的数据！");
            }

        } else {

            responseData.setCode(400);

            responseData.setMsg("请输入要查询的内容！");
        }
        return responseData;
    }
}
